// import {Actionsheet, TransferDom} from 'vux'
import Actionsheet from 'vux/src/components/actionsheet/index.vue'
import TransferDom from 'vux/src/directives/transfer-dom/index'
import CONSTANT from '@/common/constants.js'
import http from '@/common/http.js'
export default {
  name: 'donation',
  components: {
    Actionsheet
  },
  directives: {
    TransferDom
  },
  data () {
    return {
      show: true,
      showcancel: false,
      form: '',
      id: '',
      requestSecret: '',
      product_id: '',
      event_id: '',
      userId: '',
      event_idss: '',
      theme: '',
      eventAbstract: '',
      money: ''
    }
  },
  mounted () {
    // this.id = this.$route.query.id
    this.product_id = this.$route.query.product_id
    this.requestSecret = this.$route.query.requestSecret
    console.log(this.requestSecret)
    console.log(this.product_id)
    http.post(CONSTANT.PRODUCT_SHOW, {product_id: this.product_id}, (res) => {
      console.log(res)
      if (res.code == 200) {
        this.event_idss = res.obj.event_id
        this.theme = res.obj.theme
        this.eventAbstract = res.obj.eventAbstract
        this.money = res.obj.money
        var ua = navigator.userAgent.toLowerCase()
        var isWeixin = ua.indexOf('micromessenger') != -1
        if (!isWeixin) {
          console.log(this)
          // alert('请求秘钥', this.requestSecret)
          http.post('http://www.qqchou.org/zfzx/api', {'appKey': '402880e75f1520d3015f152167180000', 'requestSecret': this.requestSecret, 'type': '21', product_id: this.product_id, openid: this.openid, callBackUrl: encodeURI(CONSTANT.RECEIPT_ACHIEVE), 'orderInfo': '{"count": 1,"product_id":"' + this.product_id + '", "product_name": "' + this.theme + '","product_detail": "' + this.eventAbstract + '","price":' + this.money + '}'}, (res) => {
            console.log(res)
            var data = res.obj.form
            console.log(data)
            // document.getElementById('alipayTips').innerHTML = data
            document.body.innerHTML = data
            // 通过innerHTML添加的script代码不会自动执行，需要我们手动来执行
            var scripts = document.body.getElementsByTagName('script')
            for (var i = 0; i < scripts.length; i++) { // 一段一段执行script
              eval(scripts[i].innerHTML)
            }
          })
        }
      } else {
        alert('支付失败')
      }
    })
    // location.href = 'http://etzx.hztangong.com/zfb_alipay_zx?id=1'
    // 判断当前环境是否为微信内置浏览器
  },
  methods: {
    comeback () {
      window.history.go(-3)
    },
    comebackTwo () {
      window.location.href = 'http://www.qqchou.org/a/wxinterface/wxOAuth'
    }
  }
}
